<?php
	session_start();	
?>

<?php
	if( $_SESSION["admin"] != "" )
	{
?>
<a href="index.php?com=productimage"><b>List productimage</a></b> | <b><a href="index.php?com=productimage&func=add">Add new productimage</b></a>
<br />
<?php 
	include_once("process/productimage.php");
	$productimage = new productimage();
    if( isset($_POST['btnAdd']) )
	{	
	   $file = $_FILES["ProductImage"];
		$file_name = $file["name"];
		$file_ext = explode(".",$file_name);
		if($file["name"] == "")
		{	
			$ProductNo = stripcslashes($_POST["ProductNo"]);
            $Picture=$file_name;
            
        		$productimage->AddProductImage($ProductNo, $Picture);	
        	//	echo '<meta http-equiv="Refresh" content="0;URL=index.php?com=productimage" />';
        		//return;
            
        }
        if($file_ext[count($file_ext)-1] == "jpg" || $file_ext[count($file_ext)-1] == "jpeg" || $file_ext[count($file_ext)-1] == "gif")
		{
		     	$ProductNo = stripcslashes($_POST["ProductNo"]);
            $Picture=$file_name;
        		$productimage->AddProductImage($ProductNo, $Picture);
                move_uploaded_file($_FILES["ProductImage"]["tmp_name"],"asset/".$_FILES["ProductImage"]["name"]);	
        		echo '<meta http-equiv="Refresh" content="0;URL=index.php?com=productimage" />';
        		return;
            
		}
        else
		{
			$alert='<script type="text/javascript">
			alert("Bạn chỉ được phép chọn file có định dạng jpg, jpeg, gif");
			</script>';
			echo $alert;
		}
	}
?>

<form method="post" action="index.php?com=productimage&func=add" id="contactform" name="addcountry" onSubmit="return validateForm()" enctype="multipart/form-data">
	<table width="70%" style="font-size:10pt;">
		<tr>
			<td align="center" colspan="2" height="50"><b style="font-size:12pt; color:Blue;">Add new image for product</b></td>
		</tr>
		<tr height="26">
			<td align="right" width="120px">ProductNo :&nbsp;&nbsp;
			</td>
			<td width="140px">
            <input type="text" class="validate[required]" name="ProductNo" id="ProductNo"/><font style="color: red;"> *</font>
			</td>
        </tr>
        <tr>
			<td align="right" width="120px">Image :&nbsp;&nbsp;</td>
			<td><input type="file" name="ProductImage" id="ProductImage"/><font style="color: red;"> *</font></td>
		</tr>  	    
		<tr>
			<td></td>
			<td colspan="2" align="left" height="40">
				<input type="submit" name="btnAdd" id="btnAdd" value="Add"  />
				<input type="reset" value="Reset" />
			</td>
		</tr>
	</table>
</form>
<i>Please fill in these fields (<font style="color: red;">*</font>)</i>
<?php
     }
   else
	{
		echo "<meta http-equiv='refresh' content='0; url=login.php' />";
	}
?>